<template>
    <admin-frame>
        <header class="page-header">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>会务管理</el-breadcrumb-item>
                <el-breadcrumb-item>体验活动</el-breadcrumb-item>
                <el-breadcrumb-item>活动列表</el-breadcrumb-item>
            </el-breadcrumb>
        </header>
        <div class="mainframe-content">
            <div class="content-block">
                <div class="table-edit-header flex-row">
                    <div class="table-edit-title flex-fill">
                        <strong>活动列表</strong>
                    </div>
                    <div>
                        <router-link to="/metting/activity/edit" target="_blank">
                            <el-button type="primary" size="small">添加活动</el-button>
                        </router-link>
                    </div>
                </div>

                <el-table :data="items" style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column prop="id" width="45" type="selection"></el-table-column>
                    <el-table-column label="海报" width="70">
                        <template slot-scope="scope">
                            <el-image class="img-50" fit="cover" :src="scope.row.image" v-if="scope.row.image"></el-image>
                            <div class="img-50 img-placeholder" v-else></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="title" label="名称"></el-table-column>
                    <el-table-column prop="num" label="人数限制" width="120"></el-table-column>
                    <el-table-column prop="closing_at" width="170" label="截止日期"></el-table-column>
                    <el-table-column prop="created_at" width="170" label="创建时间"></el-table-column>
                    <el-table-column width="50">
                        <template slot-scope="scope">
                            <router-link :to="'/meeting/activity/edit?id='+scope.row.id" target="_blank">编辑</router-link>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="table-edit-footer">
                    <el-button size="small" type="primary" :disabled="selectionIds.length===0" @click="handleDelete">
                        批量删除
                    </el-button>
                    <div class="flex"></div>
                </div>
            </div>
        </div>
    </admin-frame>
</template>

<script>
    import AdminFrame from "../common/AdminFrame";

    export default {
        name: "ActivityList",
        components: {
            AdminFrame
        },
        data() {
            return {
                items: [],
                selectionIds: []
            }
        },
        mounted() {
            this.fetchList();
        },
        methods: {
            fetchList () {
                this.$get('/admin/meeting/activity/batchget').then(response => {
                    this.items = response.data.items;
                });
            },
            handleSelectionChange (val) {
                this.selectionIds = val;
            },
            handleDelete () {
                var items = this.selectionIds.map((d) => d.id);
                this.$confirm('此操作将永久删除所选话题, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.post('/admin/meeting/activity/delete', {items}).then(response => {
                        this.fetchList();
                    });
                });
            },
        }
    }
</script>

<style scoped>

</style>
